﻿using UnityEngine;
using System.Collections;

public static class MonoExtensions
{
#if UNITY_EDITOR
    public static string GetFullName(this MonoBehaviour x)
    {
        return x.transform.GetFullName() + "." + x.GetType().Name + x.CompRank();
    }
    public static int CompRank(this MonoBehaviour x)
    {
        var lst = x.gameObject.GetComponents(x.GetType());
        for(int i = 0; i < lst.Length; i++)
        {
            if (lst[i] == x) return i;
        }
        throw new System.Exception();
    }
#endif
    public static Transform FindDeep(this Transform trans,string name)
    {
        if(trans.name == name)
        {
            return trans;
        }
        else
        {
            for(int i = 0; i < trans.childCount; i++)
            {
                if(trans.GetChild(i).FindDeep(name) is Transform v)
                {
                    return v;
                }
            }

            return null;
        }
    }
}